package com.swxc.smartorder.ui.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.jaeger.library.StatusBarUtil
import com.swxc.smartorder.R
import com.swxc.smartorder.app.ConfigSPS
import com.swxc.smartorder.utils.AppSharePreferenceMgr
import com.swxc.smartorder.utils.CountDownTimerUtils


/**
 * 引导页面
 */
class SplashActivity : AppCompatActivity() {


    var mContext: Context? = null
    var mIntent: Intent? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_splash)
        StatusBarUtil.setTranslucent(this, 0)
        mContext = this
        mIntent = Intent()
        initViewAndEvent()
    }

    private fun initViewAndEvent() {
        val userToken = AppSharePreferenceMgr.get(mContext, ConfigSPS.TOKEN, "") as String

        CountDownTimerUtils.getCountDownTimer()
                .setMillisInFuture(2000)
                .setFinishDelegate {
                    if (userToken.isEmpty()) {

                        mIntent?.setClass(mContext, LoginActivity::class.java)
                        startActivity(mIntent)
                        finish()
                    } else {
                        mIntent?.setClass(mContext, WorkActivity::class.java)
                        startActivity(mIntent)
                        finish()
                    }
                }
                .start()
    }

    override fun onDestroy() {

        CountDownTimerUtils.getCountDownTimer().cancel()
        super.onDestroy()
    }
}
